const os = require('os');
const path = require('path');

/**
 * 获取 本机 ip 地址
 * @returns {string}
 */
function getIPAddress() {
    var interfaces = os.networkInterfaces();
    for (var devName in interfaces) {
        var iface = interfaces[devName];
        for (var i = 0; i < iface.length; i++) {
            var alias = iface[i];
            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                return alias.address;
            }
        }
    }
}

/**
 * 获取绝对路径
 * @param {string} dir 
 */
function resolve(dir) {
    return path.join(__dirname, '../' + dir)
}

module.exports = {
    resolve,
    getIPAddress
}